package com.onstar.cn.api;

import com.onstar.cn.api.framework.BaseApiService;
import com.onstar.cn.api.framework.ClazzInjectUtils;
import com.onstar.cn.api.framework.annotation.Path;
import com.onstar.cn.api.framework.annotation.PathParams;
import com.onstar.cn.api.framework.annotation.RequestMapping;
import com.onstar.cn.common.util.CommonUtil;
import com.onstar.cn.framework.network.entity.RequestEntity;
import com.onstar.cn.mag.enumtype.RemoteCommandsType;

//@Path("/PartnerServices/REST/VehicleServices/")
@Path("/api/v1/account")
public class VehicleService extends BaseApiService {


    private String serverURL;

    /**
     * @Description: TODO
     * @author 6335yz
     * @date 2015年8月20日 下午3:36:47
     */
    public VehicleService(String serverURL) {
        super(serverURL);
        this.serverURL=serverURL;
    }

    /**
     * @param @param  requestEntity
     * @param @param  commandType
     * @param @param  vin
     * @param @return 设定文件
     * @return RequestEntity 返回类型
     * @throws
     * @Title: commands
     * @Description: Request method:post <br/>
     * Need request Authorization and request Accept and request
     * Accept-Language <br/>
     * COMMANDS_START or COMMANDS_CANCEL_START no request body
     * <p/>
     * COMMANDS_LOCK_DOOR or COMMANDS_UNLOCK_DOOR body:
     * {"lockDoorRequest or unlockDoorRequest": { "delay": "0" } }
     * <p/>
     * COMMANDS_ALERT body: (
     * "{\"alertRequest\": {\"delay\": \"0\",\"duration\": \"60\",\"action\": [\"Honk\",\"Flash\"],\"override\": [\"DoorOpen\",\"IgnitionOn\"]}}"
     * );
     * <p/>
     * COMMANDS_TBT_ROUTE body: {"tbtDestination":
     * {"destinationLocation": {"lat": "42.593200","long":
     * "-83.490950"},"additionalDestinationInfo":
     * {"destinationType": "ST_ADDR","destinationAddress":
     * {"streetNo": "980","state": "MI","zipCode":
     * "48382","country": "USA","street": "N Commerce Rd","city":
     * "Commerce Twp"}}}}
     * <p/>
     * <p/>
     * COMMANDS_NAV_DESTINATION body: {"navDestination":
     * {"destinationLocation": {"lat": "42.328442","long":
     * "-83.039989"}
     */
    @RequestMapping("/vehicles/{vin}/commands/")
    public RequestEntity commands(RequestEntity requestEntity, RemoteCommandsType commandType, @PathParams(value = "vin") String vin,
                                  String body) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "commands", requestEntity, commandType, vin, body);
        if (!CommonUtil.isNull(body)) {
            requestEntity.setBody(body);
        }
        requestEntity.setUrl(serverURL + url + commandType.value());
        return requestEntity;
    }

    @RequestMapping("/vehicles/{vin}/navUnit/commands/")
    public RequestEntity commandsODD(RequestEntity requestEntity, RemoteCommandsType commandType, @PathParams(value = "vin") String vin,
                                     String body) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "commandsODD", requestEntity, commandType, vin, body);
        if (!CommonUtil.isNull(body)) {
            requestEntity.setBody(body);
        }
        requestEntity.setUrl(serverURL + url + commandType.value());
        return requestEntity;
    }

//	/**
//	 * @Title: diagnostics
//	 * @Description: Request method:post <br/>
//	 *               Need request Authorization and request Accept and request
//	 *               Accept-Language
//	 * @param @param requestEntity
//	 * @param @param commandType
//	 * @param @param vin
//	 * @param @return 设定文件
//	 * @return RequestEntity 返回类型
//	 * @throws
//	 */
//	@RequestMapping("vehicles/{vin}/commands/")
//	public RequestEntity diagnostics(RequestEntity requestEntity, RemoteCommandsType commandType, @PathParams("vin") String vin, String body) {
//		if (requestEntity == null) {
//			requestEntity = new RequestEntity();
//		}
//		String url = ClazzInjectUtils.injectUrl(getClass(), "diagnostics", requestEntity, commandType, vin);
//		requestEntity.setUrl(ConfigUtils.getServerUrl() + url + "diagnostics");
//		requestEntity.setBody(body);
//		return requestEntity;
//	}

    @RequestMapping("/oauth/authorize?grant_type=authorization_code&redirect_uri=http://localhost:7001&code={authCode}")
    public RequestEntity getToken(RequestEntity requestEntity, @PathParams(value = "authCode") String authCode) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "getToken", requestEntity, authCode);
        requestEntity.setUrl(serverURL + url);
        return requestEntity;
    }

    /**
     * @param @param  requestEntity
     * @param @param  vin
     * @param @param  requestId
     * @param @return 设定文件
     * @return RequestEntity 返回类型
     * @throws
     * @Title: pollingVehicleStatus
     * @Description: Request the status of a previous request, completed or not
     * Request method:GET CommandResponseEntity
     */
    @RequestMapping("/vehicles/{vin}/requests/{requestId}")
    public RequestEntity pollingVehicleStatus(RequestEntity requestEntity, @PathParams("vin") String vin,
                                              @PathParams("requestId") String requestId) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "pollingVehicleStatus", requestEntity, vin, requestId);
        requestEntity.setUrl(serverURL + url);
        return requestEntity;
    }

    /**
     * @param @param  requestEntity
     * @param @param  vin
     * @param @param  requestId
     * @param @return 设定文件
     * @return RequestEntity 返回类型
     * @throws
     * @Title: vehicleHistory
     * @Description: Requests a specific number of requests made on a vehicle,
     * completed or not. Request method:GET
     * Response:List<CommandResponseEntity>
     */
    @RequestMapping("/vehicles/{vin}/requests")
    public RequestEntity vehicleHistory(RequestEntity requestEntity, @PathParams("vin") String vin) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "vehicleHistory", requestEntity, vin);
        requestEntity.setUrl(serverURL + url);
        return requestEntity;
    }

    @RequestMapping("/vehicles/{vin}/requests?offset={offset}&limit={limit}")
    public RequestEntity vehicleHistory(RequestEntity requestEntity, @PathParams("vin") String vin, @PathParams("offset") String offset, @PathParams("limit") String limit) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "vehicleHistory", requestEntity, vin, offset, limit);
        requestEntity.setUrl(serverURL + url);
        return requestEntity;
    }

    /**
     * @param @return 设定文件
     * @return RequestEntity    返回类型
     * @throws
     * @Title: getHotsSpotInfo
     * @Description: TODO
     */
    @RequestMapping("/vehicles/{vin}/hotspot/commands/")
    public RequestEntity commondHotSpot(RequestEntity requestEntity, @PathParams("vin") String vin, RemoteCommandsType commandsType, String body) {
        if (requestEntity == null) {
            requestEntity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "commondHotSpot", requestEntity, vin, commandsType, body);
        String commandValue = "";
        if (commandsType == RemoteCommandsType.COMMAND_GETHOTSPOTINFO) {
            commandValue = "getInfo";
        } else {
            commandValue = "setInfo";
        }
        requestEntity.setUrl(serverURL + url + commandValue);
        requestEntity.setBody(body);
        return requestEntity;
    }

    /**
     * @param @return 设定文件
     * @return RequestEntity    返回类型
     * @throws
     * @Title: commands
     * @Description: 获取车辆的Service Feature
     */
    @RequestMapping("/vehicles/{vin}/commands")
    public RequestEntity commands(RequestEntity requestEntity, @PathParams("vin") String vin) {
        return getURLRequestEntity("commands", "", requestEntity, vin);
//		if (requestEntity == null) {
//			requestEntity = new RequestEntity();
//		}
//		String url = ClazzInjectUtils.injectUrl(getClass(), "commands", requestEntity, vin);
//		requestEntity.setUrl(serverURL + url);
//		return requestEntity;
    }
}

